home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
environ
/
getenv2.asm
< prev
next >
Wrap
Assembly Source File
|
1988-01-01
|
2KB
|
77 lines
; getenv2.asm
;
; This routine finds the system wide environment string
; and returns its segment and size. Getenv2 was written to be
; called from C, and requires the large memory model. When called
; as getenv2(&envseg), envseg will contain the segment of the environment.
; The value of getenv2 will be the environment size.
; Compiled with Microsoft Macro Assembler ver 4.0 and written to be
; called from Microsoft C.
;
PSPSEG segment para at 0
org 014H ;segment address of critical error vector
ERRSEG dw ?
PSPSEG ends
INCLUDE HEAD.H
public _getenv2
_TEXT segment
_GETENV2 proc far
push bp
mov bp,sp
push ds
push di
mov ax,__psp ;get the psp segment saved by Microsoft and put
mov es,ax ;it in es for getting critical error segment.
assume es:pspseg ;let the assembler know this.
mov dx,errseg ;get the calling program's segment from the
mov es,dx ;error vector and put it in es.
mov dx,es:[0014h] ;get Command.com's critical error segment
mov es,dx ;and put it in es.
mov bx,word ptr es:[002CH] ;Command.com's environment segment
cmp bx,0 ;vector should be zero.
jnz failed ;if not then we have failed.
mov bx,dx ;if it is, then assume the environment string
dec bx ;follows this program. Point es at
mov es,bx ;the segment allocation info, and
add bx,word ptr es:[0003] ;skip forward to next alloc segment.
add bx,2 ;must add 2 paras to get over info.
les di,[bp+6] ;get address of argument pointer-a far pointer
mov es:[di],bx ;return environment segment, after that
dec bx ;backup 16 bytes from environment to
mov es,bx ;get the segment allocation info.
mov ax,word ptr es:[0003] ;fetch size of environment segment,
shl ax,1 ;multiply that by 16,
shl ax,1 ;to get the environment string size.
shl ax,1
shl ax,1
pop di
pop ds
pop bp
ret
failed: ;Could not locate the environment
mov dx,offset DGROUP:message
mov ah,9
int 21h ;Use Dos to print failure message.
pop di
pop ds
pop bp
ret
_GETENV2 endp
_TEXT ends
_DATA segment
extrn __psp:word ;Microsoft stores the psp segment here.
message db 'Getenv2 could not locate environment',0dh,0ah,'$'
_DATA ends
end